#include "monster.h"
#include "map.h"
#include "game.h"
#include "random.h"
#include "player.h"
#include "buffs.h"

Monster::Monster( int sStr, int sDex, int sInt, int randomlyDistributedPoints )
: Creature( sStr, sDex, sInt, randomlyDistributedPoints )
{
}

Monster::~Monster()
{
}

bool Monster::OnAction( int* speedMod )
{
    Actor* a = GetMap()->GetGame().GetPlayer();
    int x = int( a->GetX() ) - int( GetX() );
    int y = int( a->GetY() ) - int( GetY() );

    if ( abs( x ) <= 1 && abs( y ) <= 1 && Random::Int( 4 ) == 0 && a != 0 ) {
        a->Call< BIOnSetFire >();
        return true;
    }
    *speedMod += 5;

    int dx = 0;
    int dy = 0;
    if ( ( abs( x ) >= abs( y ) || Random::Int( 2 ) == 0 ) && x > 0 )
        dx = 1;
    if ( ( abs( x ) >= abs( y ) || Random::Int( 2 ) == 0 ) && x < 0 )
        dx = -1;
    if ( ( abs( y ) >= abs( x ) || Random::Int( 2 ) == 0 ) && y > 0 )
        dy = -1;
    if ( ( abs( y ) >= abs( x ) || Random::Int( 2 ) == 0 ) && y < 0 )
        dy = 1;
    *speedMod += 2;

    uint d = uint( dy * 3 + 5 + dx );
    bool moved;
    Call< BIOnMove >( &d, &moved );
    if ( d == 1 || d == 3 || d == 7 || d == 9 ) {
        int speedBase;
        Call< BISpeed >( &speedBase );
        *speedMod += int( speedBase * 0.414 + 0.5 );
    }
    return true;
}